package com.rxy.demo.service;

import com.rxy.demo.mapper.*;
import com.rxy.demo.pojo.DO.AddressInfo;
import com.rxy.demo.pojo.DO.ClassInfo;
import com.rxy.demo.pojo.DO.UserInfo;
import com.rxy.demo.pojo.DTO.UserAddressRela;
import com.rxy.demo.pojo.DTO.UserClassRela;
import com.rxy.demo.pojo.UserAddressClassBean;
import com.rxy.demo.pojo.VO.UserAddressClassVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    @Autowired
    private AddressInfoMapper addressInfoMapper;

    @Autowired
    private ClassInfoMapper classInfoMapper;

    @Autowired
    private UserAddressRelaMapper userAddressRelaMapper;

    @Autowired
    private UserClassRelaMapper userClassRelaMapper;

    public String register(UserAddressClassVO userAddressClassVO){
        String username=userAddressClassVO.getUsername();
        String password=userAddressClassVO.getPassword();
        String name=userAddressClassVO.getName();
        Integer age=userAddressClassVO.getAge();
        Integer sex=userAddressClassVO.getSex();

        String province=userAddressClassVO.getProvince();
        String city=userAddressClassVO.getCity();
        String area=userAddressClassVO.getArea();
        String county=userAddressClassVO.getCounty();

        String className=userAddressClassVO.getClassName();
        String classNumber=userAddressClassVO.getClassNumber();

        UserInfo userInfo=new UserInfo();
        userInfo.setUsername(username);
        userInfo.setPassword(password);
        userInfo.setName(name);
        userInfo.setAge(age);
        userInfo.setSex(sex);
        userInfoMapper.insert(userInfo);

        AddressInfo addressInfo=new AddressInfo();
        addressInfo.setProvince(province);
        addressInfo.setCity(city);
        addressInfo.setArea(area);
        addressInfo.setCounty(county);
        addressInfoMapper.insert(addressInfo);

        ClassInfo classInfo=new ClassInfo();
        classInfo.setClassName(className);
        classInfo.setClassNumber(classNumber);
        classInfoMapper.insert(classInfo);

        UserAddressRela userAddressRela=new UserAddressRela();
        userAddressRela.setUserId(userInfo.getId());
        userAddressRela.setAddressId(addressInfo.getId());
        userAddressRelaMapper.insert(userAddressRela);

        UserClassRela userClassRela=new UserClassRela();
        userClassRela.setUserId(userInfo.getId());
        userClassRela.setClassId(classInfo.getId());
        userClassRelaMapper.insert(userClassRela);

        return "注册成功";
    }

    public UserInfo Login(UserInfo userInfo){
        /*UserAddressClassBean userAddressClassBean=new UserAddressClassBean();

        UserInfo user=userInfoMapper.selectOne(userInfo);
        userAddressClassBean.setUserInfo(user);

        UserClassRela userClassRela=new UserClassRela();
        userClassRela.setUserId(user.getId());

        UserClassRela userClassRela1=userClassRelaMapper.selectOne(userClassRela);

        ClassInfo classInfo=new ClassInfo();
        classInfo.setId(userClassRela1.getClassId());
        userAddressClassBean.setClassInfo(classInfoMapper.selectOne(classInfo));

        UserAddressRela userAddressRela*/
        return userInfoMapper.selectOne(userInfo);
    }
}
